#ifndef SYSTEM_HPP
#define SYSTEM_HPP

#include "types.hpp"
#include "interrupts.hpp"

namespace system {

    inline  byte  inportb(word port)           { byte data; asm volatile("in  %[data], %[port]": [data]"=a" (data): [port]"Nd" (port)); return data; }
    inline  void outportb(word port, byte data){            asm volatile("out %[port], %[data]"::[data] "a" (data), [port]"Nd" (port));              }

    inline  word  inportw(word port)           { byte data; asm volatile("in  %[data], %[port]": [data]"=a" (data): [port]"Nd" (port)); return data; }
    inline  void outportw(word port, word data){            asm volatile("out %[port], %[data]"::[data] "a" (data), [port]"Nd" (port));              }

    inline dword  inportd(word port)           { byte data; asm volatile("in  %[data], %[port]": [data]"=a" (data): [port]"Nd" (port)); return data; }
    inline  void outportd(word port,dword data){            asm volatile("out %[port], %[data]"::[data] "a" (data), [port]"Nd" (port));              }

    inline void halt() __attribute__((noreturn));
    inline void halt(){ asm volatile("cli"); while(true) asm volatile("hlt");}

    void fatal_error(const char * message) __attribute__((noreturn));

    void beep_on(int freq);
    void beep_off();
    //void beep(int freq, int duration);

}

#endif // SYSTEM_HPP
